package org.jobtask.ui;

import java.awt.Color;
import java.awt.Component;

import javax.swing.BorderFactory;
import javax.swing.JLabel;
import javax.swing.JList;
import javax.swing.JTextField;
import javax.swing.ListCellRenderer;

public class ListGroupLabel extends JTextField implements ListCellRenderer{

	/**
	 * 
	 */
	private static final long serialVersionUID = 1293488132476358034L;

	public ListGroupLabel(){
		this.setOpaque(true);
	}

	@Override
	public Component getListCellRendererComponent(JList list, Object value,
			int index, boolean isSelected, boolean cellHasFocus) {
		if (value != null)
        {
			    String v=value.toString();
                setText(v.length()>3?v.substring(0,3):v);
                setToolTipText(value.toString());
                setFont(UIConst.FONT14);
                setHorizontalAlignment(JLabel.CENTER);
        }
		
        if (isSelected) {
            setBackground(new Color(138,151,164));
            setForeground(list.getSelectionForeground());
            setBorder(BorderFactory.createRaisedBevelBorder());
        }else {
        	setBorder(BorderFactory.createEtchedBorder());
            setBackground(list.getBackground());
            setForeground(list.getForeground());
        }
        return this;
	}
}
